<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
  $_conn=mysql_connect('localhost','root','') or die(mysql_errno());
   mysql_select_db('new',$_conn) or die(mysql_errno());
   mysql_query("SET NAMES UTF8") or die(mysql_errno());
if(isset($_GET['page'])){
    $_page=$_GET['page'];
    if(empty($_page)||$_page<0||!is_numeric($_page)){//为空 小于零 不是字符窜
        $_page=1;
    }else{
        $_page=intval($_page);//取整
    }
}else{
    $_page=1;
}
   $_pagesize=3;
   $_num=mysql_num_rows(mysql_query("SELECT id FROM list"));
   if($_num==0){  //数据路没有数据的情况
   $_pageabsolute=1;
}else{
$_pageabsolute=ceil($_num/$_pagesize);
}
if($_page>$_pageabsolute){//页数大于总页数的情况
    $_page=$_pageabsolute;
}
$_pagenum=($_page-1)*$_pagesize; 
   $_result=mysql_query("SELECT id,title,author,content,date FROM list ORDER BY date ASC LIMIT $_pagenum,$_pagesize")or die(mysql_error());
   $_clean=array(); 
  
?>
 <html>
   <head>
    <title>新闻显示</title>   
     <link rel="stylesheet" type="html/css" href="style/look.css"/>
   </head> 
 <body>
    <div id="new">
        <p>新闻显示</p>
     </div>
               <?php             
                    if($_page==1){
                        $_header='首页';
                        $_top='上一页';
                    }else{
                        $_header= '<a href="look.php">首页</a>';
                       $_top ='<a href="look.php?page='.($_page-1).'">上一页</a>'; 
                    }
                    if($_page==$_pageabsolute){
                        $_end='尾页';
                       $_down='下一页';
                    }else{
                        $_end= '<a href="look.php?page='.$_pageabsolute.'">尾页</a>';
                        $_down='<a href="look.php?page='.($_page+1).'">下一页</a>'; 
                    }    
          ?>  
     <div id="table">
      <form>
        <table>
        <tr><td  colspan="6"><strong>欢迎您登录新闻发布系统</strong></td></tr>
        <tr><th>ID</th><th>主题</th><th>作者</th><th>内容</th><th>时间</th><th>删除</th></tr>
       <?php
      while ($_rows=mysql_fetch_array($_result,MYSQL_ASSOC)){
       $_clean['id']=$_rows['id'];
       $_clean['title']=$_rows['title'];
       $_clean['author']=$_rows['author'];
       $_clean['content']=$_rows['content'];
       $_clean['date']=$_rows['date'];    
      ?>
      <tr><td><?php echo $_clean['id']?></td><td><?php echo $_clean['title']?></td><td><?php echo $_clean['author']?></td><td><?php echo $_clean['content']?></td><td><?php echo $_clean['date']?></td><td><a href="delete.php?id=<?php echo $_clean['id']?>" onClick="return confirm('确认要删除？');">删除</a></td></tr>
     <?php }?>
        <tr><td  colspan="6"><?php echo $_header ?> | <?php echo $_top ?> | <?php echo $_down ?> | <?php echo $_end ?> | 总共有<?php echo $_num ?>条记录 | 每页显示<?php echo $_pagesize ?>条 | 共有<?php echo $_pageabsolute ?>页 | 当前是第<?php echo $_page ?>页 | <a href="index.php">返回</a> </td></tr>
      </table>
     
   </form>
     </div> 
   
 </body>   
    
</html>
